package similarity;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import linkprediction.Edge;
import linkprediction.Graph;
import linkprediction.Node;
import linkprediction.Ranking;

public abstract class NetworkSimilarity extends Similarity {

	protected Set<Node> intersection(Set<Node> neighbors, Set<Node> neighbors2) {
		Set<Node> intersection = new HashSet<Node>(neighbors);
		intersection.retainAll(neighbors2);
		return intersection;
	}

	protected Set<Node> union(Set<Node> neighbors, Set<Node> neighbors2) {
		Set<Node> union = new HashSet<Node>(neighbors);
		union.addAll(neighbors2);
		return union;
	}

	public abstract double getScore(Graph aGraph, Node v1, Node v2);

	public Ranking compute(Graph aGraph , Set<Node> core,  Map<Node, Set<Node>> oldEdges) {

		Ranking ranking = new Ranking();
		double scoreXY = 0.0;
		for (Node x : core) {
			for (Node y : core) {
				if (x != y) {
					if (oldEdges.containsKey(x) && oldEdges.get(x).contains(y)) {
						continue;
					}
					scoreXY = this.getScore(aGraph, x, y);
					ranking.put(new Edge(x, y), scoreXY);
				}
			}

		}
		return ranking;
	}

}